package com.cnpc.ds.service.impl;

import com.cnpc.ds.entity.OmsSysUser;
import com.cnpc.ds.mapper.OmsSysUserMapper;
import com.cnpc.ds.service.IOmsSysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cnpc.ds.utils.PageInfoUtil;
import com.cnpc.ds.utils.SqlUtil;
import org.springframework.stereotype.Service;
import com.cnpc.eisc.base.pojo.PageInfo;
import com.cnpc.eisc.base.pojo.Result;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 作者
 * @since 2024-10-15
 */
@Service
public class OmsSysUserServiceImpl extends ServiceImpl<OmsSysUserMapper, OmsSysUser> implements IOmsSysUserService {

    @Override
    public PageInfo<OmsSysUser> query(PageInfo<OmsSysUser> page,String sort,Boolean isAsc,OmsSysUser omsSysUser){
        QueryWrapper<OmsSysUser> queryWrapper = Wrappers.query(omsSysUser);
        queryWrapper.orderBy(SqlUtil.sortFieldCheck(sort),isAsc,sort);
        Page<OmsSysUser> wherePage = new Page<>(page.getPageNum(), page.getPageSize());
        Page<OmsSysUser> entityPage = this.baseMapper.selectPage(wherePage, queryWrapper);
        return PageInfoUtil.getPageInfo(entityPage);
    }

    @Override
    public Integer add(OmsSysUser omsSysUser){
        this.saveOrUpdate(omsSysUser);
        return 1;
    }

    @Override
    public Integer delete(List<String> ids){
        int res = baseMapper.deleteBatchIds(ids);
        return res;
    }

    @Override
    public OmsSysUser detail(String id){
        OmsSysUser entity = baseMapper.selectById(id);
        return entity;
    }
}
